package com.sgb.kjwl.view.ui.adapter.self.publish;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.LeaseFactoryEntity;
import com.sgb.kjwl.view.ui.activity.self.publish.LeaseFactoryActivity;
import com.sgb.kjwl.view.ui.fragment.self.CarStateFragment3;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class FactoryStateAdapter extends BaseRecycleAdapter<LeaseFactoryEntity> {
    private TextView delView;
    private TextView editView;
    private TextView upView;
    private TextView downView;
    private TextView tvTime;
    private TextView tvType;
    private View lineView;
    private LinearLayout llHouse;
    private ItemCallBack itemCallBack;

    public FactoryStateAdapter(Context context, List<LeaseFactoryEntity> datas) {
        super(context, R.layout.item_factory_state, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final LeaseFactoryEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        llHouse = holder.getItem().findViewById(R.id.ll_item_house);
        tvType = holder.getItem().findViewById(R.id.tv_type);
        delView = holder.getItem().findViewById(R.id.del_view);
        editView = holder.getItem().findViewById(R.id.edit_view);
        upView = holder.getItem().findViewById(R.id.up_view);
        downView = holder.getItem().findViewById(R.id.down_view);
        lineView = holder.getItem().findViewById(R.id.line_view);
        tvTime = holder.getItem().findViewById(R.id.tv_startTime);
        tvTime.setText(DateUtils.stampToDay(entity.getUpdateTime()));

        if (!TextUtils.isEmpty(entity.getCategory())) {
            tvType.setText(entity.getCategory());
        }

        if ("0".equals(entity.getState())) {
            upView.setVisibility(View.GONE);
            downView.setVisibility(View.GONE);
            delView.setVisibility(View.VISIBLE);
            editView.setVisibility(View.VISIBLE);
        } else if ("1".equals(entity.getState())) {
            upView.setVisibility(View.GONE);
            downView.setVisibility(View.VISIBLE);
            delView.setVisibility(View.GONE);
            editView.setVisibility(View.GONE);
        } else if ("2".equals(entity.getState())) {
            upView.setVisibility(View.VISIBLE);
            downView.setVisibility(View.GONE);
            delView.setVisibility(View.VISIBLE);
            editView.setVisibility(View.VISIBLE);
        } else if ("3".equals(entity.getState())) {
            upView.setVisibility(View.GONE);
            downView.setVisibility(View.GONE);
            delView.setVisibility(View.VISIBLE);
            editView.setVisibility(View.VISIBLE);
        } else if ("4".equals(entity.getState())) {
            upView.setVisibility(View.GONE);
            downView.setVisibility(View.GONE);
            delView.setVisibility(View.GONE);
            editView.setVisibility(View.GONE);
            lineView.setVisibility(View.GONE);
        }

        delView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.del(entity.getId());
                }
            }
        });
        upView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.up(entity.getId());
                }
            }
        });
        downView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.down(entity.getId());
                }
            }
        });
        editView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LeaseFactoryActivity.start(context, entity.getId());
            }
        });

        llHouse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.detail(entity.getId());
                }
            }
        });
    }

    public void setItemCallBack(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }

    public interface ItemCallBack {
        void del(String id);

        void up(String id);

        void down(String id);

        void detail(String id);
    }
}
